let { projectRootPath } = require("../../../util/index");
let { getNewApp } = require(`${projectRootPath}/app/index.js`);
let {
  createRole,
  getRoleByPagination,
  removeRoleByUuid,
  editRoleByUuid,
  getRoleByAll,
} = require(`${projectRootPath}/service/role/index.js`);
let app = getNewApp();
// 创建权限
app.post("/create", async (req, res) => {
  try {
    let result = await createRole(req.body);
    res.send({ data: result, code: 20000 });
  } catch (error) {
    res.send({ data: {}, message: error.message, code: 20001 });
  }
});
// 获取权限分页数据
app.post("/get/pagination", async (req, res) => {
  try {
    let result = await getRoleByPagination(req.body);
    res.send({ data: result, code: 20000 });
  } catch (error) {
    res.send({ data: {}, message: error.message, code: 20001 });
  }
});
// 通过 uuid 编辑权限
app.post("/edit/uuid", async (req, res) => {
  try {
    let result = await editRoleByUuid(req.body);
    res.send({ data: result, code: 20000 });
  } catch (error) {
    res.send({ data: {}, message: error.message, code: 20001 });
  }
});
// 通过 uuid 删除权限
app.post("/remove/uuid", async (req, res) => {
  try {
    let result = await removeRoleByUuid(req.body);
    res.send({ data: result, code: 20000 });
  } catch (error) {
    res.send({ data: {}, message: error.message, code: 20001 });
  }
});
// 获取全部权限
app.post("/get/all", async (req, res) => {
  try {
    let result = await getRoleByAll();
    res.send({ data: result, code: 20000 });
  } catch (error) {
    res.send({ data: {}, message: error.message, code: 20001 });
  }
});
module.exports = app;
